import * as dayjs from "dayjs"

export default class Ret<P extends unknown> {
    public data: P
    public code: number
    public message: string
    public success: boolean
    private timeStamp = dayjs().format('YYYY-MM-DD HH:mm:ss')
    
    static success<T>(data?: T | undefined, message?:string) {
        const ret = new Ret<T>()
        ret.code = 200
        ret.data = data
        ret.message = message || ''
        ret.success = true
        return ret
    }
    static fail(code?: number, message?:string) {
        const ret = new Ret<undefined>()
        ret.code = code || 500
        ret.message = message || '操作失败'
        ret.success = false
        return ret
    }
}